package cn.lcsjsxy.yxz.day.IO;

import javax.sound.sampled.Line;
import java.io.*;

//字符流
public class Characterstream1 {
    public static void main(String[] args) {

        //文件复制~缓冲~字符串

        // TODO 源文件
        File srcFile = new File("D:\\yang\\idea\\day10\\data\\word.txt");
        // TODO 数据目的地文件对象(自动生成)
        File destFile = new File("D:\\yang\\idea\\day10\\data\\word.txt.copy");

        //字符输入流(管道对象)
        BufferedReader reader = null;
        //字符输出流(管道对象)
        PrintWriter writer = null;

        try {
            reader = new BufferedReader(new FileReader(srcFile));
            writer = new PrintWriter(destFile);

            //打开阀门,流转数据(输入)
//            int data = -1;
            //读取文件中的一行数据
            String line = null;

            while ((line = reader.readLine()) != null) {
                System.out.println(line);
                writer.println(line);
            }
            //刷写数据
            writer.flush();

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (writer != null) {
                writer.close();
            }


        }

    }
}
